﻿using Datos.Interfaces;
using Entidad;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using Microsoft.Practices.EnterpriseLibrary.Data;
using System.Data;
using Dapper;
using DapperExtensions;

namespace Datos.Repositories
{
    public class TipoIvaRepository : ITipoIvaRepository
    {
        private readonly Microsoft.Practices.EnterpriseLibrary.Data.Database _db;

        static TipoIvaRepository()
        {
            //DatabaseFactory.SetDatabaseProviderFactory(new DatabaseProviderFactory(), false);
        }

        public TipoIvaRepository()
        {
            _db = DatabaseFactory.CreateDatabase("RealConnection");
        }

        public IList<TipoIva> FindAll()
        {
            using(IDbConnection conn = _db.CreateConnection())
            {
                const string query = "SELECT * FROM TipoIva";
                return conn.Query<TipoIva>(query).ToList();
            }
        }

        public IQueryable<TipoIva> Find(Expression<Func<Entidad.TipoIva, bool>> predicate)
        {
            throw new NotImplementedException();
        }

        public TipoIva FindById(int id)
        {
            TipoIva tipoIva;
            using(IDbConnection conn = _db.CreateConnection())
            {
                const string query = @"SELECT * FROM TipoIva
                                        WHERE Id = @id";
                tipoIva = conn.Query<TipoIva>(query, 
                    new { id = id }).SingleOrDefault();
            }
            return tipoIva;
        }

        public int Add(TipoIva newEntity)
        {
            throw new NotImplementedException();
        }

        public bool Remove(int id)
        {
            throw new NotImplementedException();
        }

        public int Modify(TipoIva entity)
        {
            throw new NotImplementedException();
        }
    }
}
